//引入组件
 import mradio from "components/radio/page-radio.vue"

 export default {
 	//注册组件
 	components: {
 		mradio
 	},
 	data() {
 		return {
 			imgUrl: this.baseApi + '/file/getImgStream?idFile=',
 			uploadAction: this.baseApi + '/file/upload',
 			header: {
 				Authorization: '',
 				RAuthorization: '',
 			},
 			order: {
 				orderSn: '',
 				orderid: '',
 				items: [{
 					imgs: [],
 					goodMark: 0,
 					content: ""
 				}],

 				orderMark: 0,
 				expMark: 0,
 				serverMark: 0
 			},
 			fileList: [],
 			errorType: ['message'],
 			fileTemp: {}

 		}
 	},
 	onLoad(option) {
 		this.order.orderSn = option.orderSn;
 		this.order.id = option.orderid;
 		this.header.Authorization = this.vuex_token;
 		this.header.RAuthorization = this.vuex_rtoken;
 		this.getData()
 	},
 	methods: {
 		getData() {
 			this.$u.get('user/order/' + this.order.orderSn).then(res => {

 				res.orderMark = this.order.orderMark;
 				res.expMark = this.order.expMark;
 				res.serverMark = this.order.serverMark;

 				for (let index in res.items) {
 					res.items[index].goodMark = 0;
 					res.items[index].content = "";
 					res.items[index].imgs = [];
 				}
 				this.order = res;

 			});
 		},
		checkPublish(){
			
			
			for (let index in this.order.items) {
				if(this.order.items[index].goodMark == 0){
					this.$u.toast('请评论商品描述相符');
					return false;
				}
				if(this.order.items[index].content == "" || this.order.items[index].content == undefined){
					this.$u.toast('请评论商品');
					return false;
				}
			}
			
			
			if(this.order.orderMark == 0){
				this.$u.toast('请评论订单描述相符');
				return false;
			}
			
			if(this.order.expMark == 0){
				this.$u.toast('请评论订单快递服务');
				return false;
			}
			
			if(this.order.serverMark == 0){
				this.$u.toast('请评论订单服务态度');
				return false;
			}
			
			return true;
		},
 		//发布评论
 		publishContent() {
 			
			if(!this.checkPublish()){return;}
			
 			this.$u.post('user/order/pl/pls001', {
 				userOrderComment: this.order
 			}).then(res => {
 				this.$u.toast('提交成功');
 				this.$u.route({
 					url: "/pages1/order/list"
 				})
 			});

 		},
 		openPage(url) {
 			this.$u.route({
 				url: url
 			})
 		},
 		changeFile(res, index, lists, name) {

 			if (res.statusCode != 200 || this.fileTemp == null) {
 				return;
 			}


 			let data = JSON.parse(res.data);
 			if (data.code == "20000") {
 				this.fileTemp.imgs.push(data.data.realFileName);

 			}


 		},
 		uploadSuccess(data) {

 			this.fileTemp = data;

 		},
 		uploadError() {
 			this.$u.toast('上传失败');
 		},

 		uploadRemove(index, lists, name) {
 			this.order.item.imgs.splice(index, 1);
 		},
		goodMarkChange(val){
			if("2"==val){
				this.$u.toast('中评48小时后显示')
			}else
			
			if("3"==val){
				this.$u.toast('差评48小时后显示')
			}
		},

 		contact() {
 			this.$u.toast('敬请期待')
 		}

 	}
 }
